home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / amitcp / sys / synch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  4.9 KB  |  185 lines

  1. /*
  2.  * $Id: synch.h,v 1.18 1994/04/02 10:29:54 jraja Exp $
  3.  *
  4.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5.  *                    Helsinki University of Technology, Finland.
  6.  *                    All rights reserved.
  7.  *
  8.  * HISTORY
  9.  * $Log: synch.h,v $
  10.  * Revision 1.18  1994/04/02  10:29:54  jraja
  11.  * Changed "wmesg" to const.
  12.  *
  13.  * Revision 1.17  1993/06/04  11:16:15  jraja
  14.  * Fixes for first public release.
  15.  *
  16.  * Revision 1.16  1993/05/24  19:28:56  ppessi
  17.  * Changed signal handling mechanism in tsleep_main() and WaitSelect()
  18.  *
  19.  * Revision 1.15  1993/05/17  01:02:04  ppessi
  20.  * Changed RCS version
  21.  *
  22.  * Revision 1.14  1993/04/19  22:35:05  jraja
  23.  * Fixed return value of splsoftclock(), splnet() and splimp() (with !DEBUG).
  24.  *
  25.  * Revision 1.13  93/04/13  22:01:32  22:01:32  jraja (Jarno Tapio Rajahalme)
  26.  * Added argument name to the spl_n prototype :-)
  27.  * 
  28.  * Revision 1.12  93/04/12  00:01:52  00:01:52  jraja (Jarno Tapio Rajahalme)
  29.  * Added ULONG *sigmp argument to tsleep_main().
  30.  * 
  31.  * Revision 1.11  93/04/05  15:00:50  15:00:50  jraja (Jarno Tapio Rajahalme)
  32.  * Added more efficient spl implementation when not debugging.
  33.  * Added spl return typedef spl_t.
  34.  * 
  35.  * Revision 1.10  93/04/05  09:31:33  09:31:33  jraja (Jarno Tapio Rajahalme)
  36.  * Changed includes to use <sys/time.h> (again) (by ppessi).
  37.  * 
  38.  * Revision 1.9  93/03/04  09:39:30  09:39:30  jraja (Jarno Tapio Rajahalme)
  39.  * Changed _AMIGA_API_H_ to AMIGA_API_H.
  40.  * 
  41.  * Revision 1.8  93/03/03  15:58:46  15:58:46  jraja (Jarno Tapio Rajahalme)
  42.  * Cleanup.
  43.  * 
  44.  * Revision 1.7  93/03/03  12:27:18  12:27:18  jraja (Jarno Tapio Rajahalme)
  45.  * Changed incomplete structure definitions to #includes
  46.  * 
  47.  * Revision 1.6  93/02/24  12:56:39  12:56:39  jraja (Jarno Tapio Rajahalme)
  48.  * Changed sleep_init() and spl_init() to return BOOL.
  49.  * 
  50.  * Revision 1.5  93/02/17  12:55:54  12:55:54  jraja (Jarno Tapio Rajahalme)
  51.  * Added prototypes for tsleep sub-functions.
  52.  * 
  53.  * Revision 1.4  93/02/04  18:19:47  18:19:47  jraja (Jarno Tapio Rajahalme)
  54.  * Added sleep_init(), tsleep() and wakeup() prototypes.
  55.  * Removed extern definitions of splsemaphore and spl_level, because they
  56.  * are needed only internally to kern/kern_synch.c.
  57.  * 
  58.  * Revision 1.3  92/12/22  00:12:16  00:12:16  jraja (Jarno Tapio Rajahalme)
  59.  * spl-definitions (written from scratch, really...)
  60.  * 
  61.  * Revision 1.2  92/11/20  15:57:01  15:57:01  jraja (Jarno Tapio Rajahalme)
  62.  * Added #ifndef AMITCP's to make this compile.
  63.  * 
  64.  * Revision 1.1  92/11/20  15:48:05  15:48:05  jraja (Jarno Tapio Rajahalme)
  65.  * Initial revision
  66.  * 
  67.  */
  68.  
  69. #ifndef SYS_SYNCH_H
  70. #define SYS_SYNCH_H
  71.  
  72. #ifndef SYS_TYPES_H
  73. #include <sys/types.h>
  74. #endif
  75.  
  76. #ifndef EXEC_TYPES_H
  77. #include <exec/types.h>
  78. #endif
  79.  
  80. #ifndef SYS_TIME_H
  81. #include <sys/time.h>
  82. #endif
  83.  
  84. #if !defined(AMIGA_INCLUDES_H) && !defined(DEBUG)
  85. #include <kern/amiga_includes.h> /* for the inline spl_n() */
  86. #endif
  87.  
  88. extern BOOL sleep_init(void);
  89. extern void tsleep_send_timeout(struct SocketBase *, const struct timeval *);
  90. extern void tsleep_abort_timeout(struct SocketBase *, const struct timeval *);
  91. extern void tsleep_enter(struct SocketBase *, caddr_t, const char *);
  92. extern int  tsleep_main(struct SocketBase *, ULONG blockmask);
  93. extern int  tsleep(struct SocketBase *, caddr_t, const char *,const struct timeval *);
  94. extern void wakeup(caddr_t);
  95.  
  96. /*
  97.  * Spl-levels used in this implementation
  98.  */
  99. #define SPL0         0
  100. #define SPLSOFTCLOCK 1
  101. #define SPLNET       2
  102. #define SPLIMP       3
  103.  
  104. /*
  105.  * Spl-function prototypes and definitions.
  106.  *
  107.  * spl_t is the return type of the spl_n(). It should be used when defining
  108.  * storage to store the return value, using int may be little slower :-) 
  109.  */
  110.  
  111. extern BOOL spl_init(void);
  112.  
  113. #ifdef DEBUG
  114.  
  115. typedef int spl_t;
  116.  
  117. extern spl_t spl_n(spl_t newlevel);
  118.  
  119. #define spl0()          spl_n(SPL0)
  120. #define splsoftclock()  spl_n(SPLSOFTCLOCK)
  121. #define splnet()        spl_n(SPLNET)
  122. #define splimp()        spl_n(SPLIMP)
  123. #define splx(s)         spl_n(s)
  124.  
  125. #else
  126.  
  127. typedef BYTE spl_t;        /* the type of SysBase->TDNestCnt */
  128.  
  129. extern struct ExecBase * SysBase;
  130.  
  131. static inline spl_t
  132. #if __SASC
  133. spl_n(int new_level)        /* int because SAS can't inline otherwise :( */
  134. #else
  135. spl_n(spl_t new_level)
  136. #endif
  137. {
  138.   spl_t old_level = SysBase->TDNestCnt;
  139.  
  140.   if (new_level != SPL0)
  141.     SysBase->TDNestCnt = new_level;
  142.   else {
  143.     SysBase->TDNestCnt = 1;
  144.     Permit();
  145.   }
  146.   return old_level;
  147. }
  148.  
  149. static inline spl_t
  150. #if __SASC
  151. spl_const(int new_level)    /* int because SAS can't inline otherwise :( */
  152. #else
  153. spl_const(spl_t new_level)
  154. #endif
  155. {
  156.   spl_t old_level = SysBase->TDNestCnt;
  157.  
  158.   SysBase->TDNestCnt = new_level;
  159.  
  160.   return old_level;
  161. }
  162.  
  163. static inline spl_t
  164. spl_0(void)
  165. {
  166.   spl_t oldlevel = SysBase->TDNestCnt;
  167.  
  168.   if (oldlevel != SPL0) {
  169.     SysBase->TDNestCnt = 1;
  170.     Permit();
  171.   }
  172.  
  173.   return oldlevel;
  174. }
  175.  
  176. #define spl0()          spl_0()
  177. #define splsoftclock()  spl_const(SPLSOFTCLOCK)
  178. #define splnet()        spl_const(SPLNET)
  179. #define splimp()        spl_const(SPLIMP)
  180. #define splx(s)         spl_n(s)
  181.  
  182. #endif /* DEBUG */
  183.  
  184. #endif /* !SYS_SYNCH_H */
  185.